﻿using System;
using DDotNet.ORM.ORMapping.Attribute;
using DDotNet.ORM.ORMapping.Attribute.DirectAccess;
using DDotNet.ORM.ORMapping.OREntity;

namespace GenericTests.Entities
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable()]
        [DBMapping("MainDB")]
    [DirectEntityMapping("tb_Customer", AllowDelete = true, AllowInsert = true, AllowUpdate = true)]
    public sealed class Customer : BusinessEntityBase
    {
        #region Construtor

        public Customer()
        {
            this._Shops = new ShopCollection();
        }

        #endregion

        private int _ID;

        /// <summary>
        /// 
        /// </summary>
        [EntityPrimaryKey(true)]
        [PropertyMapping("IDCustomer")]
        public int ID
        {
            get { return this._ID; }
            set
            {
                this._ID = value;
                base.MarkDirty("ID");
            }
        }


        private string _Name;

        /// <summary>
        ///
        /// </summary>
        [PropertyMapping("Name")]
        public string Name
        {
            get { return this._Name; }
            set
            {
                this._Name = value;
                base.MarkDirty("Name");
            }
        }


        
        private ShopCollection _Shops;

        [ChildrenPropertyMapping("IDCustomer")]
        [ChildrenPropertySettings(CascadeDelete = true, CascadeUpdate = true, AutomaticLinkLoad = true)]
        public ShopCollection Shops
        {
            get { return this._Shops; }
            set
            {
                this._Shops = value;

                // Configura o Pai do Endereço
                if (this._Shops != null)
                {
                    this._Shops.Parent = this;
                }

                base.MarkDirty("Shops");
            }
        }
        
    }
}